API Documentation
Public Member Functions | List of all members
nkGraphics::Mesh Class Reference

Holds information about a mesh. Used as a basis to render 3d models. More...

Inheritance diagram for nkGraphics::Mesh:
nkGraphics::Resource nkExport::Exportable

Public Member Functions

 Mesh ()
 
virtual ~Mesh ()
 
const BoundingBoxgetBounds () const
 
nkMemory::BufferView< unsigned char > getVertexBuffer (unsigned int index) const
 
unsigned int getVertexBufferStride (unsigned int index) const
 
unsigned int getVertexBufferCount () const
 
nkMemory::BufferView< unsigned char > getIndexBuffer () const
 
const MeshInputLayoutgetInputLayout () const
 
unsigned int getId () const
 
virtual unsigned int getVertexCount () const
 
virtual unsigned int getIndexCount () const
 
PRIMITIVE_TOPOLOGY getTopology () const
 
INDEX_FORMAT getIndexFormat () const
 
bool getAutoComputeBounds () const
 
void setBounds (const BoundingBox &value)
 
void addVertexBuffer (const nkMemory::BufferView< unsigned char > &view, unsigned int stride=0)
 
void addVertexBufferCopy (const nkMemory::BufferView< unsigned char > &view, unsigned int stride=0)
 
void addVertexBufferForward (nkMemory::Buffer &&buffer, unsigned int stride=0)
 
void removeVertexBuffer (unsigned int index)
 
void setIndexBuffer (const nkMemory::BufferView< unsigned char > &view)
 
void setIndexBufferCopy (const nkMemory::BufferView< unsigned char > &view)
 
void setIndexBufferForward (nkMemory::Buffer &&buffer)
 
void setInputLayout (const MeshInputLayout &layout)
 
void setId (unsigned int value)
 
void setVertexCount (int value)
 
void setIndexCount (int value)
 
void setTopology (PRIMITIVE_TOPOLOGY value)
 
void setIndexFormat (INDEX_FORMAT value)
 
void setAutoComputeBounds (bool value)
 
void computeBounds (const nkMemory::StringView &positionAttributeName)
 
virtual void freeShadowBuffers ()
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkGraphics::Resource
 Resource ()
 
 Resource (const nkMemory::StringView &path)
 
virtual ~Resource ()
 
virtual bool load ()=0
 
virtual void unload ()=0
 
bool isReadyForRendering () const
 
bool isUnloaded () const
 
RESOURCE_LOAD_STATE getLoadState () const
 
nkMemory::StringView getResourcePath () const
 
RESOURCE_TYPE getResourceTypeName () const
 
nkMemory::StringView getResourceName () const
 
bool getHidden () const
 
virtual void setResourcePath (const nkMemory::StringView &path)
 
void setResourceName (const nkMemory::StringView &name)
 
void setHidden (bool value)
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable ()
 
virtual ~Exportable ()
 

Detailed Description

Holds information about a mesh. Used as a basis to render 3d models.

See MeshManager::createOrRetrieve() to allocate new instances.

Constructor & Destructor Documentation

◆ Mesh()

nkGraphics::Mesh::Mesh ( )

◆ ~Mesh()

virtual nkGraphics::Mesh::~Mesh ( )
virtual

Destructor.

Member Function Documentation

◆ getBounds()

const BoundingBox& nkGraphics::Mesh::getBounds ( ) const
Returns
The bounds of the meshes, for reading purpose.

◆ getVertexBuffer()

nkMemory::BufferView<unsigned char> nkGraphics::Mesh::getVertexBuffer ( unsigned int  index) const

Gives access to a given vertex buffer CPU memory.

Parameters
indexThe index of the buffer to query the memory from.
Returns
A view over the buffer memory.
Remarks
This method works as long as the shadow buffers have not been freed. It only has access to the CPU data.

◆ getVertexBufferStride()

unsigned int nkGraphics::Mesh::getVertexBufferStride ( unsigned int  index) const

Gives access to the stride of a given vertex buffer.

Parameters
indexThe index of the vertex buffer to query from.
Returns
The stride of given vertex buffer. It will either be the one specified when adding the buffer, or the automatically computed one if not.

◆ getVertexBufferCount()

unsigned int nkGraphics::Mesh::getVertexBufferCount ( ) const
Returns
The vertex buffer count.

◆ getIndexBuffer()

nkMemory::BufferView<unsigned char> nkGraphics::Mesh::getIndexBuffer ( ) const

Gives access to the index buffer CPU memory.

Returns
A view over the buffer memory.
Remarks
This method works as long as the shadow buffers have not been freed. It only has access to the CPU data.

◆ getInputLayout()

const MeshInputLayout& nkGraphics::Mesh::getInputLayout ( ) const

Gives access to the input layout of the mesh, for reading purposes.

Returns
The input layout currently used by the mesh.

◆ getId()

unsigned int nkGraphics::Mesh::getId ( ) const
Returns
The id of the mesh.

◆ getVertexCount()

virtual unsigned int nkGraphics::Mesh::getVertexCount ( ) const
virtual
Returns
The number of vertices.

◆ getIndexCount()

virtual unsigned int nkGraphics::Mesh::getIndexCount ( ) const
virtual
Returns
The number of indices.

◆ getTopology()

PRIMITIVE_TOPOLOGY nkGraphics::Mesh::getTopology ( ) const
Returns
The topology used by the mesh.

◆ getIndexFormat()

INDEX_FORMAT nkGraphics::Mesh::getIndexFormat ( ) const
Returns
The index data format used.

◆ getAutoComputeBounds()

bool nkGraphics::Mesh::getAutoComputeBounds ( ) const
Returns
Whether the mesh auto-computes its bounds (true) or not (false).

◆ setBounds()

void nkGraphics::Mesh::setBounds ( const BoundingBox value)

Allows to override the bounds of the mesh.

Parameters
valueThe bounds for the mesh to use.

◆ addVertexBuffer()

void nkGraphics::Mesh::addVertexBuffer ( const nkMemory::BufferView< unsigned char > &  view,
unsigned int  stride = 0 
)

Adds a vertex buffer, by referencing memory.

Parameters
viewThe memory to reference.
strideThe stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.
Remarks
With this method, the buffer simply gets referenced for later loading operation. This requires the memory given to remain available through the whole loading process. Use this method if you know memory lifetime is long enough for the mesh to use it.

◆ addVertexBufferCopy()

void nkGraphics::Mesh::addVertexBufferCopy ( const nkMemory::BufferView< unsigned char > &  view,
unsigned int  stride = 0 
)

Adds a vertex buffer, by copying memory.

Parameters
viewThe memory to copy.
strideThe stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.
Remarks
With this method, the buffer gets copied over. This implies a new allocation, and a copy operation. This function can be used to make sure data is safe within the mesh, without having to invalidate input.

◆ addVertexBufferForward()

void nkGraphics::Mesh::addVertexBufferForward ( nkMemory::Buffer &&  buffer,
unsigned int  stride = 0 
)

Adds a vertex buffer, by forwarding memory.

Parameters
bufferThe memory to forward.
strideThe stride of the buffer given (number of bytes to advance to get to next vertex information). If left to 0, it will be automatically computed from the layout, assuming tightly packed data.
Remarks
With this method, the buffer needs to be moved. This means that the memory will be forwarded into the mesh's own memory, invalidating input. This function can be used if memory will not be reused afterwards, and an efficient way of passing memory is wanted.

◆ removeVertexBuffer()

void nkGraphics::Mesh::removeVertexBuffer ( unsigned int  index)

Removes a vertex buffer.

Parameters
indexThe index of the vertex buffer to remove from memory.

◆ setIndexBuffer()

void nkGraphics::Mesh::setIndexBuffer ( const nkMemory::BufferView< unsigned char > &  view)

Sets the index buffer the mesh should use, by referencing it.

Parameters
viewThe memory to reference.
Remarks
With this method, the buffer simply gets referenced for later loading operation. This requires the memory given to remain available through the whole loading process. Use this method if you know memory lifetime is long enough for the mesh to use it.

◆ setIndexBufferCopy()

void nkGraphics::Mesh::setIndexBufferCopy ( const nkMemory::BufferView< unsigned char > &  view)

Sets the index buffer the mesh should use, by copying memory.

Parameters
viewThe memory to copy over.
Remarks
With this method, the buffer gets copied over. This implies a new allocation, and a copy operation. This function can be used to make sure data is safe within the mesh, without having to invalidate input.

◆ setIndexBufferForward()

void nkGraphics::Mesh::setIndexBufferForward ( nkMemory::Buffer &&  buffer)

Sets the index buffer the mesh should use, by forwarding memory.

Parameters
bufferThe buffer to get memory from.
Remarks
With this method, the buffer needs to be moved. This means that the memory will be forwarded into the mesh's own memory, invalidating input. This function can be used if memory will not be reused afterwards, and an efficient way of passing memory is wanted.

◆ setInputLayout()

void nkGraphics::Mesh::setInputLayout ( const MeshInputLayout layout)

Sets the input layout describing mesh data.

Parameters
layoutThe layout to use to interpret the mesh data.

◆ setId()

void nkGraphics::Mesh::setId ( unsigned int  value)

Sets the id of the mesh. Used internally for tracking.

Parameters
valueThe id to use.

◆ setVertexCount()

void nkGraphics::Mesh::setVertexCount ( int  value)

Sets the number of vertices of the mesh.

Parameters
valueThe number of vertices to use.

◆ setIndexCount()

void nkGraphics::Mesh::setIndexCount ( int  value)

Sets the number of indices of the mesh.

Parameters
valueThe number of indices to use.

◆ setTopology()

void nkGraphics::Mesh::setTopology ( PRIMITIVE_TOPOLOGY  value)

Sets the topology to use.

Parameters
valueThe primitive topology the mesh should use.

◆ setIndexFormat()

void nkGraphics::Mesh::setIndexFormat ( INDEX_FORMAT  value)

Sets the format of indices stored in the index buffer.

Parameters
valueThe index format to use.

◆ setAutoComputeBounds()

void nkGraphics::Mesh::setAutoComputeBounds ( bool  value)

Sets whether the loading step should compute the bounds of the mesh.

Parameters
valueIf the bounds should be computed (true) or not (false).

◆ computeBounds()

void nkGraphics::Mesh::computeBounds ( const nkMemory::StringView positionAttributeName)

Manually triggers a bound computing.

Parameters
positionAttributeNameThe name of the position attribute within the layout to find back position data for bounds computing.

◆ freeShadowBuffers()

virtual void nkGraphics::Mesh::freeShadowBuffers ( )
virtual

Frees the shadow buffers, aka the CPU buffers (vertex buffers and index buffer).
Can be called after loading the mesh to free requested memory.

◆ exportClassToTree()

virtual void nkGraphics::Mesh::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

Basic exporting capabilities.

Parameters
rootNodeThe tree to export to.

Implements nkExport::Exportable.

◆ importClassFromTree()

virtual void nkGraphics::Mesh::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

Basic importing capabilities.

Parameters
rootNodeThe tree to import from.

Implements nkExport::Exportable.


The documentation for this class was generated from the following file: